package com.neusoft.utils;

import lombok.Data;

/**
 * @author cpx
 * @date 2024/9/25
 * @Description
 */
@Data
public class ServerResponse<T> {
    private Integer code;
    private String message;
    private T t;

    public ServerResponse(Integer code, String message, T t) {
        this.code = code;
        this.message = message;
        this.t = t;
    }

    public ServerResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ServerResponse(String message, T t) {
        this.message = message;
        this.t = t;
    }

    public static <T> ServerResponse<T> success(Integer code, String message, T t) {
        return new ServerResponse<T>(code, message, t);
    }

    public static <T> ServerResponse<T> success(String message, T t) {
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), message, t);
    }

    public static <T> ServerResponse<T> success(String message) {
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), message);
    }

    public static <T> ServerResponse<T> success(T t) {
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), t);
    }

    public static <T> ServerResponse<T> error(Integer code, String message, T t) {
        return new ServerResponse<T>(code, message, t);
    }

    public static <T> ServerResponse<T> error(String message, T t) {
        return new ServerResponse<T>(ResponseCode.ERROR.getCode(), message, t);
    }

    public static <T> ServerResponse<T> error(String message) {
        return new ServerResponse<T>(ResponseCode.ERROR.getCode(), message);
    }

    public static <T> ServerResponse<T> error(T t) {
        return new ServerResponse<T>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getMessage(), t);
    }
}
